package com.njwb.Swing.Supplier;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

public class SupplierView extends JPanel {
    JTable supplierTable;
    DefaultTableModel supplierTableModel;
    JButton addButton;
    JButton editButton;
    JButton deleteButton;
    JButton importButton;
    JTextField searchField;
    JButton searchButton;

    public SupplierView() {
        setLayout(new BorderLayout(5, 5));
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        // 顶部面板
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
        topPanel.setBackground(new Color(240, 248, 255));
        topPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));

        searchField = new JTextField(15);
        searchButton = new JButton("搜索");
        addButton = new JButton("新增供应商");
        editButton = new JButton("修改供应商");
        deleteButton = new JButton("删除供应商");
        importButton = new JButton("导入供应商");

        Dimension btnSize = new Dimension(120, 28);
        addButton.setPreferredSize(btnSize);
        editButton.setPreferredSize(btnSize);
        deleteButton.setPreferredSize(btnSize);
        importButton.setPreferredSize(btnSize);
        searchButton.setPreferredSize(new Dimension(70, 28));

        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(new JLabel("供应商名称:"));
        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(searchField);
        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(searchButton);
        topPanel.add(Box.createHorizontalStrut(10));
        topPanel.add(addButton);
        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(editButton);
        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(deleteButton);
        topPanel.add(Box.createHorizontalStrut(5));
        topPanel.add(importButton);
        topPanel.add(Box.createHorizontalGlue());

        add(topPanel, BorderLayout.NORTH);

        // 表格
        String[] columnNames = {"编号", "名称", "供应商品", "联系人", "电话", "地址"};
        supplierTableModel = new DefaultTableModel(columnNames, 0) {
            @Override
            public boolean isCellEditable(int row, int column) { return false; }
        };
        supplierTable = new JTable(supplierTableModel);
        supplierTable.setRowHeight(28);
        supplierTable.setFont(new Font("宋体", Font.PLAIN, 14));
        supplierTable.setSelectionBackground(new Color(173, 216, 230));
        supplierTable.getTableHeader().setFont(new Font("宋体", Font.BOLD, 14));
        supplierTable.getTableHeader().setBackground(new Color(200, 220, 240));

        JScrollPane scrollPane = new JScrollPane(supplierTable);
        scrollPane.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
        add(scrollPane, BorderLayout.CENTER);
    }
}
